<template>
  <div :style="{ 'fontSize': fontSize, 'height': fontSize, 'lineHeight': fontSize }" :class="headClass" class="title-head" >
    <ToolTip v-if="element.name" :content="element.name" class="title-main"/>
    <template v-if="!isTable">
      <el-tooltip v-if="tip" placement="top" effect="dark">
        <div slot="content" style="max-width: 180px; line-height: 1.5">{{ tip }}</div>
        <tipIcon is-diy style="margin-left: 8px"/>
      </el-tooltip>
      <ToolTip v-if="describe" :content="describe" class="describe"/>
    </template>
    <slot />
  </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
  name: 'Title',
  props: {
    element: {
      type: Object,
      default: () => ({
        name: '',
        options: {
          titleLevel: 1,
          describe: ''
        }
      })
    },
    isTable: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    ...mapState({
      'showMobilePage': state => state.app.showMobilePage
    }),
    fontSize() {
      const sizes = {
        1: '16px',
        2: '14px',
        3: '12px'
      };
      return sizes[this.element.options && this.element.options.titleLevel] || '16px';
    },
    headClass() {
      return {
        'level-1': this.element.options && this.element.options.titleLevel === 1 || !this.element.options || !this.element.options.titleLevel,
        'level-2': this.element.options && this.element.options.titleLevel === 2,
        'level-3': this.element.options && this.element.options.titleLevel === 3,
        'mobile-header': this.showMobilePage && this.describe,
        'header-no-describe': this.showMobilePage && !this.describe
      };
    },
    tip() {
      return this.element.options && this.element.options.tip;
    },
    describe() {
      return this.element.options && this.element.options.describe;
    }
  }
};
</script>
<style lang="scss" scoped>
.title-head {
  font-weight: bold;
  color:rgba(51,51,51,1);
  flex: 1;
  align-items: center;
  display: flex;
  position: relative;
  .title-main {
    max-width: 500px;
  }
  .right-tip{
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 14px;
    color: #999999;
    opacity: 1;
  }
  .describe {
    max-width: 330px;
    font-size:12px;
    font-weight: bold;
    color:#999999;
    line-height:14px;
    margin-left: 4px;
  }
}
.mobile-header {
  .title-main {
    max-width: 36% !important;
  }
  .describe {
    max-width: 50%;
  }
}
.header-no-describe {
  .title-main {
    max-width: 90% !important;
  }
}
.level-1 {
  &::before {
    position: relative;
    content: '';
    width: 3px;
    height: inherit;
    display: inline-block;
    background-color: #406EFF;
    vertical-align: bottom;
    top: 0px;
    margin-right: 6px;
  }
}
.level-2 {
  &::before {
    position: relative;
    content: '';
    width: 3px;
    height: 3px;
    display: inline-block;
    background-color: #406EFF;
    vertical-align: bottom;
    top: 0px;
    margin-right: 6px;
  }
}
.level-3 {
  &::before {
    position: relative;
    content: '';
    width: 3px;
    height: inherit;
    visibility: hidden;
    vertical-align: bottom;
    top: 0px;
    margin-right: 6px;
  }
}
</style>
